﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VLog;
namespace CommonExceptioin
{
    /// <summary>
    /// 默认的异常处理策略
    /// </summary>
    public class DefaultExceptionPolicy : IExceptionPolicy
    {
        private readonly IVLog _iVlog;
        public DefaultExceptionPolicy(IVLog iVlog)
        {
            this._iVlog = iVlog;
        }
        public DefaultExceptionPolicy()
            : this(VLog.VLogFactory.CreateVLog())
        {

        }
        #region IExceptionPolicy 成员

        /// <summary>
        /// 是否由系统自己去处理这个异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public bool HandlerException(object sender, Exception exception)
        {
            if (exception.IsFatal())//属于给定的系统性异常时，就写入日志，否则就抛出异常
            {
                _iVlog.Error(exception.Message);
                return true;
            }
            return false;
        }

        #endregion
    }
}
